package com.yt.app.provider.service.impl;

import com.yt.app.core.interfaces.UserOrderService;
import com.yt.app.core.model.UserOrder;
import com.yt.app.core.utils.Constant;
import com.yt.app.provider.dao.UserOrderDao;
import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import com.yt.core.service.GenericServiceImpl;
import sun.rmi.rmic.Constants;

import java.util.List;

public class UserOrderServiceImpl extends GenericServiceImpl<UserOrder, Long> implements UserOrderService {
	private UserOrderDao dao;

	public UserOrderServiceImpl() {
	}

	public UserOrderServiceImpl(UserOrderDao dao) {
		super(dao);
		this.dao = dao;
	}

	@Override
	public UserOrder getByOrderNo(String orderNumber) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_orderNo_S_EQ", orderNumber);
		List<UserOrder> list = this.dao.find(filter);
		if(list != null && !list.isEmpty()){
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<UserOrder> getByUid(Long uid){
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_uid_L_EQ", String.valueOf(uid));
		filter.addFilter("Q_orderStatus_S_EQ", Constant.ORDER_STATUS.PAID.value());
		List<UserOrder> list = this.dao.find(filter);
		return list;
	}

	@Override
	public void updateOrderStatus(Long orderId, String status) {
		dao.updateOrderStatus(orderId, status);
	}


}
